import React, { Component } from 'react';
import { withRouter } from 'react-router-dom'
import RouterView from './routers/index'
import connect from './connect'
import Storage from '@/utils/storage.js'


@connect
@withRouter
class App extends Component {
  constructor(props) {
    super(props);
    this.accessUri = ['/fav', "/click"]
  }

  checkLogin(pathname) {
    const bool = this.accessUri.some(item => {
      return new RegExp(item).test(pathname)
    })
    if (bool && !Storage.get('islogin')) {
      this.props.history.push('/login')
      return;
    }
  }

  componentDidMount() {
    this.checkLogin(this.props.location.pathname)

    this.props.history.listen(location => {
      this.checkLogin(location.pathname)
    })
  }

  render() {
    return (
      <>
        <h1 style={{ display: this.props.footerMenu }}>模拟底部菜单显示隐藏</h1>
        <RouterView />
      </>
    );
  }
}

export default App;
